package com.gqzdev.xblog.service.impl;


import com.gqzdev.xblog.dao.NewsuserDao;
import com.gqzdev.xblog.entity.Newsuser;
import com.gqzdev.xblog.service.NewsuserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (Newsuser)表服务实现类
 *
 * @author ganquanzhong
 * @since 2020-03-07 21:46:53
 */
@Service("newsuserService")
public class NewsuserServiceImpl implements NewsuserService {
    @Resource
    private NewsuserDao newsuserDao;

    @Override
    public Newsuser queryByNamePwd(Newsuser newsuser) {
        List<Newsuser> users = newsuserDao.login(newsuser);
        if(users.size()>0){
            return users.get(0);
        }else {
            return null;
        }
    }

    @Override
    public Integer getByNamePwd(Newsuser newsuser) {
        return  newsuserDao.getCount(newsuser);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param uid 主键
     * @return 实例对象
     */
    @Override
    public Newsuser queryById(Integer uid) {
        return this.newsuserDao.queryById(uid);
    }

    @Override
    public List<Newsuser> queryByName(String name) {
        return this.newsuserDao.queryByName(name);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Newsuser> queryAllByLimit(int offset, int limit) {
        return this.newsuserDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param newsuser 实例对象
     * @return 实例对象
     */
    @Override
    public Newsuser insert(Newsuser newsuser) {
        this.newsuserDao.insert(newsuser);
        return newsuser;
    }

    /**
     * 修改数据
     *
     * @param newsuser 实例对象
     * @return 实例对象
     */
    @Override
    public Newsuser update(Newsuser newsuser) {
        this.newsuserDao.update(newsuser);
        return this.queryById(newsuser.getUid());
    }

    /**
     * 通过主键删除数据
     *
     * @param uid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer uid) {
        return this.newsuserDao.deleteById(uid) > 0;
    }


    @Override
    public List<Newsuser> findList(Map<String, Object> queryMap) {
        return newsuserDao.findList(queryMap);
    }

    @Override
    public int getTotal(Map<String, Object> queryMap) {
        return newsuserDao.getTotal(queryMap);
    }

    @Override
    public int delete(String ids) {
        return newsuserDao.delete(ids);
    }

    @Override
    public int check(String ids) {
        return newsuserDao.check(ids);
    }
}